<?php

/**
 * 前台首页控制器
 * @author yupoxiong<i@yupoxiong.com>
 */

declare(strict_types=1);

namespace app\index\controller;

use think\Request;
use Exception;

class FinancialController extends IndexBaseController
{
    /**
     * @throws Exception
     */
    public function index(): string
    {
        $data = cache('list600');
        if (!$data) {
            $data = file_get_contents('https://93.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124021067371822918557_1704966146148&pn=1&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=1619074599229208|0|1|0|web&fid=f3&fs=b:MK0216&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152&_=1704966146209');
            if ($data) {
                cache("list600", $data, 600);
                cache('listall', $data);
            } else {
                $data = cache('listall');
            }
        }

        $str1 = explode('})', $data)[0] . '}';
        $str2 = '{' . explode('({', $str1)[1];
        $resdata = json_decode($str2, true);
        $this->assign('list', $resdata['data']['diff']);
        return  $this->fetch();
    }
}
